package com.ny.demo627;

import java.util.Scanner;

public class Test01 {


    public static void showWelcomeMenu() {
        System.out.println("欢迎使用职工工资计算系统");
        System.out.println("1. 开始计算工资");
        System.out.println("2. 退出");
    }

    public static int getMenuChoice(Scanner scanner) {
        int choice;
        while (true) {
            System.out.print("请输入菜单编号（1-开始，2-退出）：");
            if (scanner.hasNextInt()) {
                choice = scanner.nextInt();
                if (choice == 1 || choice == 2) {
                    return choice;
                } else {
                    System.out.println("输入不合法，请输入1或2。");
                }
            } else {
                System.out.println("请输入有效的数字。");
                scanner.next(); // 清除非法输入
            }
        }
    }

    public static Employee getEmployeeInfo(Scanner scanner) {
        System.out.print("请输入职工姓名：");
        String name = scanner.next();

        System.out.print("请输入职工ID：");
        String id = scanner.next();

        return new Employee(name, id);
    }

    public static Salary getSalaryInfo(Scanner scanner) {
        System.out.print("请输入基本工资：");
        double baseSalary = scanner.nextDouble();

        System.out.print("请输入奖金：");
        double bonus = scanner.nextDouble();

        System.out.print("请输入扣款：");
        double deduction = scanner.nextDouble();

        return new Salary(baseSalary, bonus, deduction);
    }

    public static void calculateAndDisplaySalary(Employee employee, Salary salary) {
        double netSalary = salary.baseSalary + salary.bonus - salary.deduction;

        System.out.println("\n工资计算结果如下：");
        System.out.println("职工姓名：" + employee.name);
        System.out.println("职工ID：" + employee.id);
        System.out.println("基本工资：" + salary.baseSalary);
        System.out.println("奖金：" + salary.bonus);
        System.out.println("扣款：" + salary.deduction);
        System.out.println("实发工资：" + netSalary);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            showWelcomeMenu();
            int choice = getMenuChoice(scanner);

            if (choice == 2) {
                System.out.println("感谢使用，再见！");
                break;
            }

            Employee employee = getEmployeeInfo(scanner);
            Salary salary = getSalaryInfo(scanner);
            calculateAndDisplaySalary(employee, salary);

            System.out.println("\n是否继续？1. 是  2. 否");
            int continueChoice = scanner.nextInt();
            if (continueChoice != 1) {
                System.out.println("感谢使用，再见！");
                break;
            }
        }

        scanner.close();
    }



}
